package top.saodisheng.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.ServletRequestHandledEvent;

/**
 * 目前Spring MVC没有监听ServletRequestHandledEvent请求处理事件
 * 不过咱们可以自己写一个监听器用于获取请求信息
 *
 * @author saodisheng
 * @date 2021/10/12
 */
@Component
@Slf4j
public class ServletRequestHandledEventListener implements ApplicationListener<ServletRequestHandledEvent> {
	@Override
	public void onApplicationEvent(ServletRequestHandledEvent event) {
		log.info("请求描述：{}", event.getDescription());
		log.info("请求路径：{}", event.getRequestUrl());
		log.info("开始时间：{}", event.getTimestamp());
		log.info("请求耗时：{}", event.getProcessingTimeMillis());
		log.info("状 态 码：{}", event.getStatusCode());
		log.info("失败原因：{}", event.getFailureCause());
	}
}
